package com.gitee.qdbp.base.tags;

import java.io.IOException;
import javax.servlet.jsp.JspWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 标签工具类
 *
 * @author zhaohuihua
 * @version 140619
 * @since v1.0
 */
public class TagTools {

    /**
     * 日志对象
     */
    private static final Logger log = LoggerFactory.getLogger(TagTools.class);

    /**
     * 生成Attribute, 如name="xxx", 如果value==null则返回空字符串
     *
     * @param name 名称
     * @param value 值
     * @return Attribute
     */
    public static String createAttribute(String name, String value) {
        StringBuilder buffer = new StringBuilder();
        if (value != null) {
            buffer.append(" ").append(name).append("=\"").append(value).append("\"");
        }
        return buffer.toString();
    }

    /**
     * 输出HTML内容
     *
     * @param out JspWriter
     * @param html HTML内容
     */
    public static void print(JspWriter out, String html) {
        // 输出标签内容
        try {
            out.print(html);
        } catch (IOException e) {
            log.error("jsp write error: " + html, e);
        }
    }
}
